package jjn.daily;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jjn
 * @since 2023-09-27 22:50
 */
public class LeetCode1333 {
    public List<Integer> filterRestaurants(int[][] restaurants, int veganFriendly, int maxPrice, int maxDistance) {
        int n = restaurants.length;
        List<int[]> result = new ArrayList<>();
        for (int[] restaurant : restaurants) {
            if (veganFriendly == 1) {
                if (restaurant[2] != 1) {
                    continue;
                }
            }
            if (restaurant[4] > maxDistance || restaurant[3] > maxPrice) {
                continue;
            }
            result.add(restaurant);
        }
        result.sort((r1, r2) -> {
            if (r1[1] < r2[1]) {
                return 1;
            }
            if (r1[1] > r2[1]) {
                return -1;
            }
            return -1 * Integer.compare(r1[0], r2[0]);
        });
        List<Integer> list = new ArrayList<>();
        for (int[] res : result) {
            list.add(res[0]);
        }
        return list;
    }
    
}
